using System.Collections.Specialized;

namespace TheSalLab.MauiBehaviors;

public class MauiActionCollection : MauiBindableObjectCollection {
    public MauiActionCollection() {
        CollectionChanged += ActionCollection_OnCollectionChanged;
    }

    private void ActionCollection_OnCollectionChanged(object sender,
        NotifyCollectionChangedEventArgs e) {
        foreach (var bindable in this) {
            VerifyType(bindable);
        }
    }

    private static void VerifyType(BindableObject bindable) {
        if (bindable is not IMauiAction) {
            throw new InvalidOperationException(
                "Non-IMauiAction added to IMauiAction collection");
        }
    }
}